package com.example.shop_2212.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntity
import com.example.base.entity.CategoryEntityResult
import com.example.shop_2212.R

/**
 * 一级分类适配器
 */
class OneAdapter:BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_one) {
    //选中文字颜色和背景
    var selectType = 515
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.one_tv,item.name)
        if(item.id==selectType){
            holder.getView<TextView>(R.id.one_tv).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.one_tv).setBackgroundResource(R.drawable.bg_item_type)
        }else{
            holder.getView<TextView>(R.id.one_tv).setTextColor(Color.BLACK)
            holder.getView<TextView>(R.id.one_tv).background = null
        }
    }
    fun setType(id:Int){
        selectType = id
        notifyDataSetChanged()
    }
}